package com._119yn.host.gst200.config;

import com._119yn.host.gst200.properties.DadsProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
@EnableConfigurationProperties(DadsProperties.class)
@RequiredArgsConstructor
public class DadsConfig {

//    private final ResourceLoader resourceLoader;
//
//    @Bean
//    public Map<String, Map<String, PointTableRecord>> gst200PointTableMap() throws IOException {
//        Map<String, Map<String, PointTableRecord>> pointTable = new HashMap<>();
//        String fileName = "classpath:dev_gst2.csv";
//        Charset fileCharset = Charset.forName("GBK");
//        CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().setSkipHeaderRecord(true).get();
//        try (CSVParser parser = CSVParser.parse(resourceLoader.getResource(fileName).getInputStream(), fileCharset, format)) {
//            for (CSVRecord record : parser) {
//                PointTableRecord pointTableRecord = new PointTableRecord();
//                pointTableRecord.setSn(Integer.parseInt(StringUtils.strip(record.get("序号"))));
//                pointTableRecord.setDeviceAddress(StringUtils.strip(record.get("设备地址")));
//                pointTableRecord.setDeviceId(StringUtils.strip(record.get("设备ID")));
//                pointTableRecord.setDeviceType(StringUtils.strip(record.get("设备类型")));
//                pointTableRecord.setText(StringUtils.strip(record.get("文本信息")));
//                Map<String, PointTableRecord> map = pointTable.computeIfAbsent(pointTableRecord.getDeviceAddress(), k -> new HashMap<>());
//                map.put(pointTableRecord.getDeviceType(), pointTableRecord);
//            }
//        }
//        log.info("pointTableMap: {}", pointTable);
//        return pointTable;
//    }
}
